package com.zizo.autohome.user.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.zizo.autohome.user.bean.Potential;
import com.zizo.util.ConnectionPool;
import com.zizo.util.Util;

public class PotentialDao {
	private Connection conn;

	public void insert(Potential p) {
		PreparedStatement ps = null;
		String sql = "INSERT INTO autohome_other.other_potential(potential_user_cid,potential_bbs_cid,potential_bbs_time) values(?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, p.getUser_cid());
			ps.setInt(2, p.getBbs_cid());
			ps.setDate(3, (Date) Util.getDate(p.getTime()));
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			ConnectionPool.close(ps);
		}
	}

	public List<Integer> getIDs() {
		List<Integer> carIDs = new ArrayList<>();
		Statement st = null;
		ResultSet rs = null;
		String sql = "SELECT user_uid FROM autohome_other.other_user WHERE user_uid>13798906";
		try {
			st = conn.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				carIDs.add(rs.getInt("user_uid"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return carIDs;
	}

	public PotentialDao(Connection conn) {
		super();
		this.conn = conn;
	}

}
